import { formItemKeys, customKeys, COL_PROPS } from './constants';
import type { Form } from './interface';
// fieldList更新
export const changeFormList = (formList: Form.NewFieldItem[], updateList: Form.FieldItem[]): Form.NewFieldItem[] => {
  let list: any = formList;
  list.forEach((item: any, index: string | number) => {
    updateList.forEach((ele: any) => {
      if (item.field === ele.field) {
        list[index] = { ...item, ...ele };
        const keys: string[] = Object.keys(ele);
        keys.forEach((key: string) => {
          const val = ele[key];
          if (formItemKeys.includes(key)) {
            list[index].formItemProps[key] = val;
          } else if (customKeys.includes(key) || key === 'colProps') {
            list[index][key] = val;
          } else {
            list[index].componentProps[key] = val;
          }
        });
      }
    });
  });
  return list;
};
